/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package speedball;

import javafx.animation.*;
import javafx.animation.PathTransition.OrientationType;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.*;
import javafx.scene.effect.BlendMode;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.*;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.scene.text.Font;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import speedball.notice.ModeNoticeService;
import speedball.popup.MenuController;
import speedball.popup.MyPopup;
import speedball.popup.MyPopup.PopupHPosition;
import speedball.popup.MyPopup.PopupVPosition;
import speedball.popup.ShowPopupController;
import speedball.skincenter.SkinCenterStage;
import speedball.speedup.SpeedUpAnimationTimer;

import java.awt.*;

//import com.jfoenix.controls.JFXPopup;
//import com.jfoenix.controls.JFXPopup.PopupHPosition;
//import com.jfoenix.controls.JFXPopup.PopupVPosition;
//import fxml.demo2.BasicOpsTest;
//import fxml.demo2.Test;
//import fxml.speedball.EffectManage.Direction;

/**
 * @author Administrator
 */
public class SpeedBallApplication extends Application {

    //	private double xOffSet= 0;
//	private double yOffSet= 0;
    private double oldScreenX = 0;
    private double oldScreenY = 0;
    private double oldStageX = 0;
    private double oldStageY = 0;
    private static boolean flag = true;
    private static double opacity = 1.00D;

//	private double initOffsetX =10.00D;
//	private double initOffsetY = 50.00D;

    private double initOffsetX = 100.00D;
    private double initOffsetY = 120.00D;



    //	private double progressBarMaxValue =100.00D;
//    private double progressBarMinValue =0.00D;
//    private double progressBarVisibleMaxValue =100.00D;
//    private double progressBarVisibleMinValue =0.00D;
//    private double progressBarCurrentValue =90.00D;
//
//	private double progressBarWidth =65.00D;
//    private double progressBarValueWidth = progressBarCurrentValue/progressBarMaxValue*(progressBarWidth-2);
    private boolean upExist = false;
    private boolean leftExist = false;
    private boolean rightExist = false;


    private Point2D initOffsetPoint = new Point2D(initOffsetX, initOffsetY);
//	private static Path path = BasicOpsTest.drawShapes2(true);
//
//	private static Path path2 = BasicOpsTest.drawShapes2(false);

    private static boolean switchFlag = true;
    private static boolean borderVaryFlag = true;
    private double currentValue = 80.00D;
    private boolean autoPadding = true;
    //    final BorderPane  borderPane = PanelManage.createBorderPanel(stage.getWidth(), stage.getHeight(), null, null, null, null, null); ;
    private BorderPane borderPane = PanelManage.createBorderPanel(180.00D, 120.00D, null, null, null, null, null);
    ;

    private Color rippleRed = Color.rgb(255, 148, 110);
    private Color rippleGreen = Color.rgb(137, 230, 169);

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader myMenufXMLLoader = new FXMLLoader(getClass().getClassLoader().getResource("./fxml/mymenu.fxml"));
        FXMLLoader showPopupFXMLLoader = new FXMLLoader(getClass().getClassLoader().getResource("./fxml/showPopup.fxml"));

//		AnchorPane manager = controller.getManager();
//		AnchorPane anchorFather=controller.getAnchorFather();
        Parent root2 = myMenufXMLLoader.load();
        MenuController menuController = myMenufXMLLoader.getController();
        ScrollPane pane234 = (ScrollPane) root2;




        Parent showPopupRoot = showPopupFXMLLoader.load();
        ShowPopupController showPopupController = showPopupFXMLLoader.getController();
        borderPane.setUserData(true);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.getIcons().add(new Image("file:/C://ooopic_1558629542.png"));

        SkinCenterStage skinCenterStage = new SkinCenterStage(stage);


//    	stage.setIconified(true);

//		FXMLLoader fXMLLoader =new FXMLLoader(getClass().getResource("first4.fxml"));
//		Parent root = fXMLLoader.load();

//		FXMLLoader fXMLLoader2 =new FXMLLoader(getClass().getResource("first3.fxml"));
//		Test controller = fXMLLoader.getController();
//		AnchorPane manager = controller.getManager();
//		AnchorPane anchorFather=controller.getAnchorFather();
//		Parent root2 = fXMLLoader2.load();
//		path.setBlendMode(BlendMode.SRC_ATOP);
//		path2.setBlendMode(BlendMode.SRC_ATOP);

        double circleSize = 30.0D;
        double rectangleHight = circleSize * 0.7D;
        double rectangleWidth = rectangleHight * 7.0D;
        double check = 10.0D;
        double expandWidth = 25.0D;

//		Group root = GroupManage.createGroup(500, 300, opacity);

        Pane root = PanelManage.createAnchorPane(0, 0, 180, 100);

        Pane paneLeft = PanelManage.createAnchorPane(0, 0, 10, 6);
        Pane paneRight = PanelManage.createAnchorPane(0, 0, 10, 6);

        Pane paneTop = PanelManage.createAnchorPane(0, 0, 10, 10);
        Pane paneBottom = PanelManage.createAnchorPane(0, 0, 10, 10);

        ObservableList<Node> children = root.getChildren();

        // ==============创建图形开始=====================


        //创建进度条=====================
        SpProgressBar spProgressBarTop = new SpProgressBar(currentValue, EffectManage.JavaFxConstants.HORIZONTAL, true, 1.00D);
        SpProgressBar spProgressBarLeft = new SpProgressBar(currentValue, EffectManage.JavaFxConstants.VERTICAL, true, 0.00D);
        SpProgressBar spProgressBarRight = new SpProgressBar(currentValue, EffectManage.JavaFxConstants.VERTICAL, true, 0.00D);
        SpProgressBar spProgressBarBottom = new SpProgressBar(currentValue, EffectManage.JavaFxConstants.HORIZONTAL, true, 0.00D);

        spProgressBarTop.setLayoutY(-10D);
        spProgressBarLeft.setLayoutX(-10D);
        spProgressBarRight.setLayoutX(170D);
        spProgressBarBottom.setLayoutY(70D);

        Circle circle = ShapeManage.createCircle(circleSize);
        ModeNoticeService modeNoticeService=new ModeNoticeService(5209,circle);

        Rectangle rect = ShapeManage.createRectangle(circleSize - check, circleSize - rectangleHight,
                rectangleWidth * 1.0, rectangleHight * 2, rectangleHight * 2, rectangleHight * 2);
        Rectangle rect2 = ShapeManage.createRectangle(circleSize - check, circleSize - rectangleHight,
                rectangleWidth * 1.0, rectangleHight * 2, rectangleHight * 2, rectangleHight * 2);

        // 右边的长方形
        Shape right = rect.subtract(rect, circle);

//        ScaleTransition rightScaleTransition = new ScaleTransition(Duration.millis(1000), right);
//        rightScaleTransition.setCycleCount(-1);
//        rightScaleTransition.setFromX(1.0D);
//        rightScaleTransition.setToX(0.4D);
//        rightScaleTransition.setToY(1.0D);
//        rightScaleTransition.setAutoReverse(true);
//        rightScaleTransition.play();
//        rightScaleTransition.

//        Scale scale=new Scale(0.4,1,0,0);
//        right.getTransforms().add(scale);

        EffectManage.createShadow(right, "#72b9da");
        Paint shadow = EffectManage.colorLinearGradient(Color.rgb(250, 250, 250), Color.rgb(240, 240, 240),
                EffectManage.Direction.TURN_DWON);

        right.setFill(shadow);

        Rectangle square = ShapeManage.createRectangle(0, 0, 60D, 60D, 55D, 50D);
        square.setStyle("-fx-border-radius: 50%; -fx-background-radius: 50%;");
        square.setBlendMode(BlendMode.EXCLUSION);

        Circle air1 = ShapeManage.createCircle(5);
        air1.setFill(rippleGreen);

        Circle air2 = ShapeManage.createCircle(4);
        air2.setFill(rippleGreen);

        Circle air3 = ShapeManage.createCircle(3);
        air3.setFill(rippleGreen);
        final Path path1 = new Path();
        path1.getElements().add(new MoveTo(0, 10));
        path1.getElements().add(new LineTo(10, -20));

        final Path path2 = new Path();
        path2.getElements().add(new MoveTo(20, 0));
        path2.getElements().add(new LineTo(24, -20));

        final Path path3 = new Path();
        path3.getElements().add(new MoveTo(40, 0));
        path3.getElements().add(new LineTo(35, -20));

//		path2.getElements().add(new CubicCurveTo(380, 0, 380, 120, 200, 120));
//		path2.getElements().add(new CubicCurveTo(0, 120, 0, 240, 380, 240));
        final PathTransition pathTransition = new PathTransition();

        pathTransition.setDuration(Duration.seconds(2.5));
//	    pathTransition.setDelay(Duration.seconds(1.5));
        pathTransition.setPath(path1);
        pathTransition.setNode(air1);
        pathTransition
                .setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
        pathTransition.setCycleCount(-1);
        pathTransition.setAutoReverse(false);
//	    pathTransition.play();
        FadeTransition ft = new FadeTransition(Duration.seconds(2.5), air1);
        ft.setFromValue(1.0);
        ft.setToValue(0.0);
        ft.setCycleCount(-1);
        ft.setAutoReverse(false);
        ScaleTransition scaleTransition = new ScaleTransition(Duration.seconds(2.5), air1);
        scaleTransition.setToX(0.5f);
        scaleTransition.setToY(0.5f);
        scaleTransition.setCycleCount(-1);
        scaleTransition.setAutoReverse(false);
        final PathTransition pathTransition2 = new PathTransition();

        pathTransition2.setDuration(Duration.seconds(1.5));
        pathTransition2.setDelay(Duration.seconds(1.2));
        pathTransition2.setPath(path2);
        pathTransition2.setNode(air2);
        pathTransition2
                .setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
        pathTransition2.setCycleCount(-1);
        pathTransition2.setAutoReverse(false);

        FadeTransition ft2 = new FadeTransition(Duration.seconds(1.5), air2);
        ft2.setFromValue(1.0);
        ft2.setToValue(0.0);
        ft2.setCycleCount(-1);
        ft2.setAutoReverse(false);

        ScaleTransition scaleTransition2 = new ScaleTransition(Duration.seconds(1.5), air2);
        scaleTransition2.setToX(0.5f);
        scaleTransition2.setToY(0.5f);
        scaleTransition2.setCycleCount(-1);
        scaleTransition2.setAutoReverse(false);

        final PathTransition pathTransition3 = new PathTransition();
        pathTransition3.setDuration(Duration.seconds(2.0));
        pathTransition3.setDelay(Duration.seconds(1.8));
        pathTransition3.setPath(path3);
        pathTransition3.setNode(air3);
        pathTransition3
                .setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
        pathTransition3.setCycleCount(-1);
        pathTransition3.setAutoReverse(false);
//	    pathTransition3.play();

        FadeTransition ft3 = new FadeTransition(Duration.seconds(2.0), air3);
        ft3.setFromValue(1.0);
        ft3.setToValue(0.0);
        ft3.setCycleCount(-1);
        ft3.setAutoReverse(false);

        ScaleTransition scaleTransition3 = new ScaleTransition(Duration.seconds(2.0), air3);
        scaleTransition3.setToX(0.5f);
        scaleTransition3.setToY(0.5f);
        scaleTransition3.setCycleCount(-1);
        scaleTransition3.setAutoReverse(false);


        NodeManage.setOffset(initOffsetPoint, air1, air2, air3);

        ParallelTransition parallelTransition = new ParallelTransition();
        parallelTransition.getChildren().addAll(ft, pathTransition, scaleTransition);
        parallelTransition.setCycleCount(Timeline.INDEFINITE);
        parallelTransition.setAutoReverse(false);

        parallelTransition.play();


        ParallelTransition parallelTransition2 = new ParallelTransition();
        parallelTransition2.getChildren().addAll(pathTransition2, ft2, scaleTransition2);
        parallelTransition2.setCycleCount(Timeline.INDEFINITE);
        parallelTransition2.setAutoReverse(false);

        parallelTransition2.play();

        ParallelTransition parallelTransition3 = new ParallelTransition();
        parallelTransition3.getChildren().addAll(pathTransition3, ft3, scaleTransition3);
        parallelTransition3.setCycleCount(Timeline.INDEFINITE);
        parallelTransition3.setAutoReverse(false);

        parallelTransition3.play();

        Ellipse ellipse = ShapeManage.createEllipse(30D, 31D, 38D);
        Shape ripple = ellipse.subtract(ellipse, circle);
        ripple.setOpacity(0.60D);
        ripple.setBlendMode(BlendMode.SRC_OVER);
        ripple.setFill(rippleGreen);
        ripple.setStroke(rippleGreen);

        Shape ripple2 = ellipse.subtract(ellipse, circle);
        ripple2.setOpacity(0.70D);
        ripple2.setRotate(90D);
        ripple2.setBlendMode(BlendMode.MULTIPLY);
        ripple2.setFill(rippleGreen);
        ripple2.setStroke(rippleGreen);

        Shape ripple3 = ellipse.subtract(ellipse, circle);
        ripple3.setOpacity(0.80D);
        ripple3.setRotate(145D);
        ripple3.setBlendMode(BlendMode.MULTIPLY);
        ripple3.setFill(rippleGreen);
        ripple3.setStroke(rippleGreen);

        double i = Integer.MAX_VALUE;
        Animation rotate = AnimationManage.setRotateAnimation(3000 * i, ripple, ripple2, ripple3);
        rotate.play();
//		Animation rotate = AnimationManage.setRotateAnimation(ripple, Duration.millis(3000 * i));	
//		Animation rotate2 = AnimationManage.setRotateAnimation(ripple2,  Duration.millis(2880 * i));
//		Animation rotate3 = AnimationManage.setRotateAnimation(ripple3,  Duration.millis(2682 * i));		
//		Animation rotate = AnimationManage.setRotateAnimation(ripple, Duration.millis(3000 * i));	
//		Animation rotate2 = AnimationManage.setRotateAnimation(ripple2,  Duration.millis(3000 * i));
//		Animation rotate3 = AnimationManage.setRotateAnimation(ripple3,  Duration.millis(3000 * i));	
//		rotate.play();
//		rotate2.play();
//		rotate3.play();

//		SequentialTransition sequentialTransition = new SequentialTransition();
//		sequentialTransition.getChildren().addAll(rotate, rotate2);
//		sequentialTransition.setCycleCount(Timeline.INDEFINITE);
//		sequentialTransition.setAutoReverse(true);
//
//		sequentialTransition.play();

//		children.addAll(circle,right,ripple);

        //progressBar2,progressValue2,top2,progressBar2,progressValue2,top2,progressBar,progressValue,top,
        NodeManage.setOffset(initOffsetPoint, spProgressBarTop, spProgressBarLeft, spProgressBarRight, spProgressBarBottom, circle, right, ripple, ripple2, ripple3);//air1,air2,air3,path1,path2,path3
        children.addAll(spProgressBarTop, spProgressBarLeft, spProgressBarRight, spProgressBarBottom, circle, right, ripple, ripple2, ripple3, air1, air2, air3);
//		children.addAll(circle, path, right, ripple, ripple2,ripple3,air1,air2,air3);
        // ==============创建图形结束=====================
        Label number = ControlManage.createNumber(circleSize * 0.30D, circleSize * 0.38D, circleSize * 2.0D * 0.6D,
                circleSize * 2.0D * 0.6D, Color.BLACK);
        number.setText(String.valueOf((int) currentValue));

        number.textProperty().addListener(listener -> {
            System.out.println(number.getText());
            if (number.getText().equals("80")) {
                rippleGreen = rippleRed;
                ripple.setFill(rippleGreen);
                ripple.setStroke(rippleGreen);
                ripple2.setFill(rippleGreen);
                ripple2.setStroke(rippleGreen);
                ripple3.setFill(rippleGreen);
                ripple3.setStroke(rippleGreen);
                air1.setFill(rippleGreen);
                air1.setStroke(rippleGreen);
                air2.setFill(rippleGreen);
                air2.setStroke(rippleGreen);
                air3.setFill(rippleGreen);
                air3.setStroke(rippleGreen);
                EffectManage.createShadow(right, "#FF8754");

                spProgressBarLeft.getValue().setFill(rippleGreen);
                spProgressBarLeft.getValue().setStroke(rippleGreen);
                spProgressBarLeft.getTop().setFill(Color.rgb(255, 107, 67));
                spProgressBarLeft.getTop().setStroke(Color.rgb(255, 107, 67));
                spProgressBarTop.getValue().setFill(rippleGreen);
                spProgressBarTop.getValue().setStroke(rippleGreen);
                spProgressBarTop.getTop().setFill(Color.rgb(255, 107, 67));
                spProgressBarTop.getTop().setStroke(Color.rgb(255, 107, 67));
                spProgressBarBottom.getValue().setFill(rippleGreen);
                spProgressBarBottom.getValue().setStroke(rippleGreen);
                spProgressBarBottom.getTop().setFill(Color.rgb(255, 107, 67));
                spProgressBarBottom.getTop().setStroke(Color.rgb(255, 107, 67));
                spProgressBarRight.getValue().setFill(rippleGreen);
                spProgressBarRight.getValue().setStroke(rippleGreen);
                spProgressBarRight.getTop().setFill(Color.rgb(255, 107, 67));
                spProgressBarRight.getTop().setStroke(Color.rgb(255, 107, 67));

//                value.setStroke(Color.rgb(113,239,124));
//                value.setFill(Color.rgb(113,239,124));
//                top.setStroke(Color.rgb(24,183,92));
//                top.setFill(Color.rgb(24,183,92));

            }
        });

        SpeedUpAnimationTimer speedUpAnimationTimer = new SpeedUpAnimationTimer(number);
        circle.setOnMouseClicked(event -> {
            speedUpAnimationTimer.start();
        });

        Label percent = ControlManage.createPercent(40.00D, circleSize * 0.6D + 5D, circleSize * 2.0D * 0.4D,
                circleSize * 2.0D * 0.4D);
        // ===========================================================
        double rowHeight = 20.0D;
        double colWidth = 34.0D;

        Label speed = ControlManage.label("14.1M/s", new Font(9.50D), colWidth + 8, rowHeight, Color.BLACK);

        Label CPU = ControlManage.label("CPU", Color.rgb(102, 102, 102));
        Label temperature = ControlManage.label("42℃", Color.rgb(13, 215, 103));
        ImageView imageView = new ImageView();

        imageView.setImage(new Image("file:C://up.png"));
//		imageView.setImage(new Image("file:C://down3.png"));
//		imageView.setImage(new Image("file:C://up.png"));

        GridPane gridPane = PanelManage.createGridPane(65.0D, 10.0D, colWidth * 2, rowHeight * 2, false);

        RowConstraints rowinfo3 = new RowConstraints();
        rowinfo3.setPrefHeight(rowHeight);

        ColumnConstraints colInfo1 = new ColumnConstraints();
        colInfo1.setPrefWidth(colWidth * 1.0D - 6);

        ColumnConstraints colInfo2 = new ColumnConstraints();
        colInfo2.setPrefWidth(colWidth * 1.0D + 10);

        gridPane.getRowConstraints().add(rowinfo3);// 2*50 percent
        gridPane.getRowConstraints().add(rowinfo3);
        gridPane.getColumnConstraints().add(colInfo1); // 25 percent
        gridPane.getColumnConstraints().add(colInfo2); // 50 percent
        rowinfo3.setVgrow(Priority.SOMETIMES);
        colInfo2.setHgrow(Priority.SOMETIMES);
        gridPane.setConstraints(imageView, 0, 0);
        gridPane.setConstraints(speed, 1, 0);
        gridPane.setConstraints(CPU, 0, 1);
        gridPane.setConstraints(temperature, 1, 1);
        ObservableList<Node> content = gridPane.getChildren();
        content.addAll(imageView, speed, CPU, temperature);

        ImageView add = new ImageView("file:C://add.png");
        ImageView add2 = new ImageView("file:C://add2.png");

        Button expand = ControlManage.createExpand(circleSize - check + rectangleWidth - expandWidth - 8.0D,
                circleSize - expandWidth / 2, expandWidth, add);

        NodeManage.setOffset(initOffsetPoint, number, percent, gridPane, expand);
        children.addAll(number, percent, gridPane, expand);
        // ======================控件添加结束=====================
        // ----------------------------------------------------------------------------------------------------------------
        Button expand2 = ControlManage.createExpand(60D - expandWidth / 2.0D, 60D - expandWidth / 2.0D, expandWidth,
                add2);

        expand2.setStyle("-fx-border-radius: 25; -fx-background-radius: 25; -fx-background-color: #3399FF;");

        Shape fd = ShapeManage.createRing(60D, 60D, 35D, 25D);
        fd.setStroke(Color.rgb(244, 244, 244));
        fd.setFill(Color.rgb(244, 244, 244));

        Group group = new Group();

        group.getChildren().add(fd);
        group.getChildren().add(expand2);
        group.setStyle("-fx-background-color:#434547;");

        Stage stage2 = new Stage();
        stage2.initStyle(StageStyle.TRANSPARENT);

        Scene scene2 = new Scene(group);
        scene2.setFill(null);
        stage2.setScene(scene2);

        expand.setOnMouseClicked(event -> {
            stage2.setX(stage.getX() + expand.getLayoutX() - 60 + expandWidth / 2.0D);
            stage2.setY(stage.getY() + expand.getLayoutY() - 60 + expandWidth / 2.0D);
            if (stage2.isShowing()) {
                root.setOpacity(root.getOpacity() + 0.5D);
                stage2.setAlwaysOnTop(!stage2.isAlwaysOnTop());
                expand.setOpacity(root.getOpacity());
                stage2.close();
            } else {
                expand.setOpacity(0D);
                System.out.println(stage2.getOpacity());
                root.setOpacity(root.getOpacity() - 0.5D);
                stage2.setAlwaysOnTop(true);
                stage2.show();
            }
        });

        rect.setFill(Color.rgb(244, 244, 244));

        double duration = 250L;
        int cycleCount = 1;

        root.setOnMousePressed(event -> {
            this.oldStageX = stage.getX();
            this.oldStageY = stage.getY();
            this.oldScreenX = event.getScreenX();
            this.oldScreenY = event.getScreenY();
        });

        //定义矩形的平移效果
        TranslateTransition translateTransition = new TranslateTransition(Duration.millis(duration), root);
        translateTransition.setCycleCount(1);
        translateTransition.setAutoReverse(false);
        ScaleTransition spProgressBarLeftScaleTransition = new ScaleTransition(Duration.millis(duration), spProgressBarLeft);
        spProgressBarLeftScaleTransition.setCycleCount(1);
        spProgressBarLeftScaleTransition.setAutoReverse(false);

        FadeTransition spProgressBarRightFadeTransition = new FadeTransition(Duration.millis(duration), spProgressBarRight);
        spProgressBarRightFadeTransition.setCycleCount(1);
        spProgressBarRightFadeTransition.setAutoReverse(true);

        FadeTransition spProgressBarBottomFadeTransition = new FadeTransition(Duration.millis(duration), spProgressBarBottom);
        spProgressBarBottomFadeTransition.setCycleCount(1);
        spProgressBarBottomFadeTransition.setAutoReverse(true);

        FadeTransition spProgressBarLeftFadeTransition = new FadeTransition(Duration.millis(duration), spProgressBarLeft);
        spProgressBarLeftFadeTransition.setCycleCount(1);
        spProgressBarLeftFadeTransition.setAutoReverse(true);
        ParallelTransition parallelTransition56 = new ParallelTransition(
                translateTransition, spProgressBarRightFadeTransition, spProgressBarBottomFadeTransition, spProgressBarLeftFadeTransition);
        parallelTransition56.setCycleCount(1);

        root.setOnMouseEntered(event -> {
            if ((boolean) borderPane.getUserData()) {
                if (leftExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    translateTransition.setFromY(0D);
                    translateTransition.setFromX(-180.00D);
                    translateTransition.setToX(0D);

                    spProgressBarRightFadeTransition.setFromValue(1.0D);
                    spProgressBarRightFadeTransition.setToValue(0.0D);
                    System.out.println("setOnMouseEntered 左边缘");
                    parallelTransition56.play();
//				ClickEvent.setCilckToggle(false, spProgressBar2, ripple, ripple2, ripple3, air1, air2, air3, right, gridPane, expand, number, percent, circle, parallelTransition, parallelTransition2, parallelTransition3);
                }
                if (rightExist) {
                    System.out.println("setOnMouseEntered 右边缘");

                    translateTransition.setFromX(root.getLayoutX() + 170D);
                    translateTransition.setFromY(0);
                    translateTransition.setToY(0);
                    translateTransition.setToX(root.getLayoutX());
                    spProgressBarLeftFadeTransition.setFromValue(1.0D);
                    spProgressBarLeftFadeTransition.setToValue(0.0D);
                    parallelTransition56.play();
                }
                if (upExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    spProgressBarBottomFadeTransition.setFromValue(1.0D);
                    spProgressBarBottomFadeTransition.setToValue(0.0D);
                    System.out.println("setOnMouseEntered 上边缘");
                    translateTransition.setFromY(-90.00D);
                    translateTransition.setToY(0D);

                    parallelTransition56.play();
//				ClickEvent.setCilckToggle(false, progressBar, progressValue, top, ripple, ripple2, ripple3, air1, air2, air3, right, gridPane, expand, number, percent, circle, parallelTransition, parallelTransition2, parallelTransition3);
                }
            }
        });

        root.setOnMouseExited(event -> {
            System.out.println("setOnMouseExited");
            if ((boolean) borderPane.getUserData()) {

                if (leftExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    System.out.println("setOnMouseExited 左边缘");
                    translateTransition.setFromX(0D);
                    translateTransition.setFromY(0D);
                    translateTransition.setToX(-180.00D);
                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(1.0D);

                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(0.0D);

                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(0.0D);
                    parallelTransition56.play();
                }
                if (rightExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    System.out.println("setOnMouseExited 右边缘");
                    translateTransition.setToY(0D);
                    translateTransition.setFromY(0D);
                    translateTransition.setFromX(root.getLayoutX());
                    translateTransition.setToX(root.getLayoutX() + 170.00D);
                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(1.0D);
                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(0.0D);
                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(0.0D);
                    parallelTransition56.play();
                }
                if (upExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(0.0D);
                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(0.0D);
                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(1.0D);
                    System.out.println("setOnMouseExited 上边缘");
                    translateTransition.setFromX(0D);
                    translateTransition.setFromY(0D);
                    translateTransition.setToY(-90.00D);
                    parallelTransition56.play();
//				ClickEvent.setCilckToggle(true, progressBar, progressValue, top, ripple, ripple2, ripple3, air1, air2, air3, right, gridPane, expand, number, percent, circle, parallelTransition, parallelTransition2, parallelTransition3);
                }
            }
        });

        Tab tab1 = new Tab("test1");
        tab1.setClosable(false);
        Button button = new Button();
        button.setText("关闭插件");
        button.setOnMouseClicked(event -> {
            if (switchFlag) {
                FadeTransition ft5 = new FadeTransition(Duration.millis(duration + 200), right);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                FadeTransition ft4 = new FadeTransition(Duration.millis(duration + 200), gridPane);
                ft4.setFromValue(1.0);
                ft4.setToValue(0.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), expand);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();
                // 创建时间
                final Timeline timeline2 = new Timeline();
                timeline2.setCycleCount(cycleCount);// 设置周期运行循环�?�?
//	    		timeline.setCycleCount(1);//设置周期运行循环�?�?

                timeline2.setAutoReverse(true);// 设置动画的自动往返效�?

                switchFlag = !switchFlag;
            } else {
                FadeTransition ft5 = new FadeTransition(Duration.millis(duration - 400), right);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();
                ft5 = new FadeTransition(Duration.millis(duration - 400), expand);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                FadeTransition ft4 = new FadeTransition(Duration.millis(duration - 400), gridPane);
                ft4.setFromValue(0.0);
                ft4.setToValue(1.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();
                // 创建时间�?
                final Timeline timeline2 = new Timeline();
                timeline2.setCycleCount(cycleCount);// 设置周期运行循环�?�?
//	    		timeline.setCycleCount(1);//设置周期运行循环�?�?
                timeline2.setAutoReverse(true);// 设置动画的自动往返效�?
                switchFlag = !switchFlag;
            }
        });

        Button button2 = new Button();
        button2.setText("关闭面板");
        button2.setLayoutX(100);
        button2.setLayoutY(100);
        button2.setOnMouseClicked(event -> {
            if (borderVaryFlag) {
                //ripple, ripple2, ripple2, ripple3, air1, air2, air3, right, gridPane, expand, number, percent, circle
                FadeTransition ft5 = new FadeTransition(Duration.millis(duration + 200), ripple);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), ripple2);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();


                ft5 = new FadeTransition(Duration.millis(duration + 200), ripple2);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), ripple3);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

//				ft5 = new FadeTransition(Duration.millis(duration + 200), air1);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();
//				
//				ft5 = new FadeTransition(Duration.millis(duration + 200), air2);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();
//				ft5 = new FadeTransition(Duration.millis(duration + 200), air3);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), right);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                FadeTransition ft4 = new FadeTransition(Duration.millis(duration + 200), gridPane);
                ft4.setFromValue(1.0);
                ft4.setToValue(0.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), expand);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), number);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), percent);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), circle);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                parallelTransition.stop();
                parallelTransition2.stop();
                parallelTransition3.stop();

                ft5 = new FadeTransition(Duration.millis(duration + 200), air1);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(1);
//				ft5.setAutoReverse(false);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration + 200), air2);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(1);
                ft5.setAutoReverse(false);
                ft5.play();
                ft5 = new FadeTransition(Duration.millis(duration + 200), air3);
                ft5.setFromValue(1.0);
                ft5.setToValue(0.0);
                ft5.setCycleCount(1);
                ft5.setAutoReverse(false);
                ft5.play();

                borderVaryFlag = !borderVaryFlag;
            } else {
//				progressBar.setVisible(borderVaryFlag);
//				progressValue.setVisible(borderVaryFlag);
//				top.setVisible(borderVaryFlag);
                //progressBar,progressValue,top
//				FadeTransition ft5 = new FadeTransition(Duration.millis(duration - 400), progressBar);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();
//				
//				
//				ft5 = new FadeTransition(Duration.millis(duration - 400), progressValue);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();
//				
//				
//				ft5 = new FadeTransition(Duration.millis(duration - 400), top);
//				ft5.setFromValue(1.0);
//				ft5.setToValue(0.0);
//				ft5.setCycleCount(cycleCount);
//				ft5.setAutoReverse(true);
//				ft5.play();


                //ripple, ripple2, ripple2, ripple3, air1, air2, air3, right, gridPane, expand, number, percent, circle
                FadeTransition ft5 = new FadeTransition(Duration.millis(duration - 400), ripple);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration - 400), ripple2);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration - 400), ripple3);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                ft5 = new FadeTransition(Duration.millis(duration - 400), right);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();
                ft5 = new FadeTransition(Duration.millis(duration - 400), expand);
                ft5.setFromValue(0.0);
                ft5.setToValue(1.0);
                ft5.setCycleCount(cycleCount);
                ft5.setAutoReverse(true);
                ft5.play();

                FadeTransition ft4 = new FadeTransition(Duration.millis(duration - 400), gridPane);
                ft4.setFromValue(0.0);
                ft4.setToValue(1.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                ft4 = new FadeTransition(Duration.millis(duration - 400), number);
                ft4.setFromValue(0.0);
                ft4.setToValue(1.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                ft4 = new FadeTransition(Duration.millis(duration - 400), percent);
                ft4.setFromValue(0.0);
                ft4.setToValue(1.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                ft4 = new FadeTransition(Duration.millis(duration - 400), circle);
                ft4.setFromValue(0.0);
                ft4.setToValue(1.0);
                ft4.setCycleCount(cycleCount);
                ft4.setAutoReverse(true);
                ft4.play();

                parallelTransition.play();
                parallelTransition2.play();
                parallelTransition3.play();

                borderVaryFlag = !borderVaryFlag;
            }
        });
        AnchorPane pane = new AnchorPane();

        HBox hbox = new HBox();
        hbox.setPadding(new Insets(0, 10, 10, 10));
        hbox.setSpacing(10);
        hbox.getChildren().addAll(button, button2);

        AnchorPane.setTopAnchor(hbox, 8.0);
        AnchorPane.setRightAnchor(hbox, 5.0);
        pane.getChildren().add(hbox);
        tab1.setContent(pane);
        Tab tab2 = new Tab("test2");
        tab2.setClosable(false);
        Tab tab3 = new Tab("test3");
        tab3.setClosable(false);
        TabPane tabPane = new TabPane(tab1, tab2, tab3);
        tabPane.setPrefSize(300, 465);
        tabPane.setLayoutX(0D);
        tabPane.setLayoutY(60D);
        tabPane.setTabMaxWidth(80D);
        tabPane.setTabMinWidth(80D);


        Pane showPopupPane = (Pane) showPopupRoot;
        showPopupController.setParentShape(circle);


        MyPopup popup4 = new MyPopup(pane234);




        MyPopup showPopup = new MyPopup(showPopupPane);


        menuController.getShowLabel().setOnMouseClicked(event->{
//            showPopup.show(root, PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);
            System.out.println("menuController.getShowButton().setOnMouseClicked(");
            showPopup.show(menuController.getShowLabel(), PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);
//            menuController.getShowButton().f
        });

//        menuController.getShowLabel().setOnMouseExited(event->{
////            showPopup.show(root, PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);
//            System.out.println("menuController.getShowButton().setOnMouseExited(");
//            if(showPopup.isShowing()){
//                showPopup.hide();
//}
//
//
//        });
        menuController.getShowLabel().focusedProperty().addListener(listener->{
                    if(showPopup.isShowing()){
                showPopup.hide();
        }
        });



        root.setOnMouseClicked(event -> {
            if (event.getButton() == MouseButton.PRIMARY) {
                System.out.println("点击了左键");

            } else if (event.getButton() == MouseButton.SECONDARY) {
                System.out.println("点击了右键");
                menuController.getScrollPane().setHvalue(0);
//                popup4.show(root, PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);
                popup4.show(root, PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);
//                showPopup.show(root, PopupVPosition.TOP, PopupHPosition.LEFT, event.getX() + 20D, event.getY() + 20D);

            } else if (event.getButton() == MouseButton.MIDDLE) {
                System.out.println("点击了中键");
            }
        });

        root.setOnMouseReleased(event -> {
            if ((boolean) borderPane.getUserData()) {
                if (leftExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    System.out.println("setOnMouseReleased ");
                    translateTransition.setFromX(0);
                    translateTransition.setFromY(0);
                    translateTransition.setToX(-180.00D);
                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(1.0D);

                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(0.0D);
                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(0.0D);
                    parallelTransition56.setCycleCount(1);
                    parallelTransition56.play();
                }
                if (rightExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    System.out.println("setOnMouseReleased ");
                    translateTransition.setFromX(root.getLayoutX());
                    translateTransition.setFromY(0);
                    translateTransition.setToY(0);
                    translateTransition.setFromY(0);
                    translateTransition.setToX(root.getLayoutX() + 170D);
                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(1.0D);

                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(0.0D);
                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(0.0D);

                    parallelTransition56.setCycleCount(1);
                    parallelTransition56.play();
                }
                if (upExist && parallelTransition56.getStatus() == Animation.Status.STOPPED) {
                    translateTransition.setFromX(0);
                    translateTransition.setFromY(0);
                    translateTransition.setToY(-90.00D);
                    spProgressBarBottomFadeTransition.setFromValue(0.0D);
                    spProgressBarBottomFadeTransition.setToValue(1.0D);
                    spProgressBarRightFadeTransition.setFromValue(0.0D);
                    spProgressBarRightFadeTransition.setToValue(0.0D);
                    spProgressBarLeftFadeTransition.setFromValue(0.0D);
                    spProgressBarLeftFadeTransition.setToValue(0.0D);
                    parallelTransition56.setCycleCount(1);
                    parallelTransition56.play();
                }
            }
        });

        root.setOnMouseDragged(event -> {
            stage.setX(event.getScreenX() - oldScreenX + oldStageX);
            stage.setY(event.getScreenY() - oldScreenY + oldStageY);

            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            if (stage.getX() < 0.0D) {
                stage.setX(0.00D);
                leftExist = true;
                System.out.println("到达左边缘");
            }
            if (stage.getX() > 0.0D) {
                leftExist = false;
                System.out.println("移开左边缘");
            }
            if (stage.getY() < 0.0D) {
                stage.setY(0.00D);
                upExist = true;
                System.out.println("到达上边缘");
            }

            if (stage.getY() > 0.0D) {
                upExist = false;
                System.out.println("移开上边缘");
            }

            if (stage.getX() > screenSize.getWidth() - stage.getWidth()) {
                stage.setX(screenSize.getWidth() - stage.getWidth());
                rightExist = true;
                System.out.println("到达右边缘");
            }

            System.out.println(screenSize.getWidth() - stage.getWidth() - stage.getX());
            System.out.println(rightExist);

            if (stage.getX() < screenSize.getWidth() - stage.getWidth() && rightExist) {
                System.out.println("移开右边缘");
                rightExist = false;
            }

        });

        stage.setAlwaysOnTop(true);
        stage.setIconified(false);
//        stage.setWidth(180.00D);
//        stage.setHeight(120.00D);
//        root.prefWidth(180.00D);
//        root.prefHeight(100.00D);
        stage.setWidth(400.0D);
        stage.setHeight(220.00D);
        root.prefWidth(400.0D);
        root.prefHeight(220.00D);

//        borderPane = PanelManage.createBorderPanel(stage.getWidth(), stage.getHeight(), null, null, null, null, root);
        borderPane.setCenter(root);

//        borderPane.prefWidth(1000.0D);
//        borderPane.prefHeight(800.00D);
        menuController.setParent(borderPane);
        menuController.setParentStage(stage);
        menuController.setSocketService(modeNoticeService);
        if(menuController.getAutoGameModeButton().isSelected()){
            if(!modeNoticeService.isOpening()){
                modeNoticeService.open();
                modeNoticeService.acceptDeal();
            }
        }else {
            if(modeNoticeService.isOpening()){
                modeNoticeService.close();
            }
        }



        menuController.setSkinCenterStage(skinCenterStage);
        borderPane.setStyle("-fx-background-color: white;");
        borderPane.setStyle("-fx-background-color: TRANSPARENT;");
//        borderPane.setStyle("-fx-background-color: white;");
        root.setStyle("-fx-background-color: TRANSPARENT;");
        paneLeft.setStyle("-fx-background-color: Blue;");
        paneTop.setStyle("-fx-background-color: green;");
        paneBottom.setStyle("-fx-background-color: yellow;");
        paneRight.setStyle("-fx-background-color: Blue;");
//        borderPane.setLeft(paneLeft);
//        borderPane.setTop(paneTop);
//        borderPane.setBottom(paneBottom);
//        borderPane.setRight(paneRight);
//        SubScene subScene=new SubScene();
//        Scene scene = new Scene(root);
        Scene scene = new Scene(borderPane);
        scene.setFill(null);
        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}